
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ScrewTurn.Wiki.PluginFramework;
using System.Text;

namespace ScrewTurn.Wiki {

	public partial class PageNotFound : BasePage {

		protected void Page_Load(object sender, EventArgs e) {
			Page.Title = Resources.Messages.PageNotFoundTitle + " - " + Settings.WikiTitle;

			if(Request["Page"] != null) {
				lblDescription.Text = lblDescription.Text.Replace("##PAGENAME##", Request["Page"]);
			}
			else {
				Response.Redirect("Default.aspx");
			}

			PrintSearchResults();
		}

		public void PrintSearchResults() {
			StringBuilder sb = new StringBuilder();

			List<SearchMatch> results = SearchTools.Search(Request["Page"]);
			if(results.Count > 0) {
				sb.Append("<p>");
				sb.Append(Resources.Messages.WereYouLookingFor);
				sb.Append("</p>");
				sb.Append("<ul>");
				PageContent c;
				for(int i = 0; i < results.Count; i++) {
					c = Content.GetPageContent(results[i].PageInfo, true);
					sb.Append(@"<li><a href=""");
					sb.Append(Tools.UrlEncode(results[i].PageInfo.Name));
					sb.Append(Settings.PageExtension);
					sb.Append(@""">");
					sb.Append(c.Title);
					sb.Append("</a></li>");
				}
				sb.Append("</ul>");
			}
			else {
				/*sb.Append("<p>");
				sb.Append(Resources.Messages.WeCouldntFind);
				sb.Append("</p>");*/
			}
			sb.Append(@"<br /><p>");
			sb.Append(Resources.Messages.YouCanAlso);
			sb.Append(@" <a href=""Search.aspx?Query=");
			sb.Append(Tools.UrlEncode(Request["Page"]));
			sb.Append(@""">");
			sb.Append(Resources.Messages.PerformASearch);
			sb.Append("</a> ");
			sb.Append(Resources.Messages.Or);
			sb.Append(@" <a href=""Edit.aspx?Page=");
			sb.Append(Tools.UrlEncode(Request["Page"]));
			sb.Append(@"""><b>");
			sb.Append(Resources.Messages.CreateThePage);
			sb.Append("</b></a> (");
			sb.Append(Resources.Messages.CouldRequireLogin);
			sb.Append(").</p>");

			lblSearchResults.Text = sb.ToString();
		}

	}

}
